package net.bxx2004.zephyr.key;

import net.bxx2004.zephyr.Zephyr;
import net.bxx2004.zephyr.network.MessageBox;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.util.InputUtil;

public class KeyBinding implements Key{
    private net.minecraft.client.option.KeyBinding binding;
    public KeyBinding(int slot,String name){
        binding = KeyBindingHelper.registerKeyBinding(new net.minecraft.client.option.KeyBinding(name, InputUtil.Type.KEYSYM,
                slot,Key.c));
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (isInput()) {
                Zephyr.message.send(new MessageBox("zephyr:zephyr","type=keyBinding;slot=" + slot + ";player=" + client.player.getName()));
            }
        });
    }

    @Override
    public boolean isInput() {
        return binding.wasPressed();
    }
}
